/**
 * \file vector.h
 * \brief A generic implementation of a vector data structure.
 **/

#ifndef R_VECTOR_H
#define R_VECTOR_H

#include "standard.h"

struct RVectorT {
  uint32_t el_size;
  uint32_t alloc_size;
  uint32_t size;
  void* data;
};
typedef struct RVectorT RVector;

/**
 * \brief Append the data at data pointer to the vector. The data is assumed
 * to be of size el_size.
 **/
void r_vector_append(RVector* vector, void* data);

/**
 * \brief Clear the vector, but expect that contents might be added soon again.
 * Thus, keep all memory you allocated for the vector.
 **/
void r_vector_clear_lazy(RVector* vector);

/**
 * \brief Get the pointer to element at position idx in the vector.
 **/
void* r_vector_get(RVector* vector, uint32_t idx);

/**
 * \brief Copy the contents of the element at idx into the buffer at
 * destination. destination must hold at least el_size bytes.
 **/
void r_vector_get_into(RVector* vector, uint32_t idx, void* destination);

/**
 * \brief Initialize a RVector structure, so that elements can be added.
 * Assume that vector->el_size is populated.
 **/
void r_vector_init(RVector* vector);

/**
 * \brief Initialize a RVector structure, initially preallocated to hold
 * size elements. Assume that vector->el_size is populated.
 **/
void r_vector_init_sized(RVector* vector, uint32_t size);

/**
 * \brief Pop an element off the end of the RVector. Together with append,
 * this can be used like a stack.
 * \return The contents of the vector are copied into the buffer given by
 * destination.
 **/
void r_vector_pop(RVector* vector, void* destination);

#endif /* R_VECTOR_H */
